/* ************************************************************************ */
/*                                                                          */
/*  Copyright (c)2005 Russell Weir | damonsbane _at_ gmail                  */
/*                                                                          */
/* This library is free software; you can redistribute it and/or            */
/* modify it under the terms of the GNU Lesser General Public               */
/* License as published by the Free Software Foundation; either             */
/* version 3.0 of the License, or (at your option) any later version.       */
/*                                                                          */
/* This library is distributed in the hope that it will be useful,          */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
/* Lesser General Public License or the LICENSE file for more details.      */
/*                                                                          */
/* ************************************************************************ */

package tzparser;
import altdate.TimeSpecification;

class ZoneChange {
	public var name(default,null) : String;
	var julian : altdate.JulianDay;
	var utcOffset : TimeSpecification;
	var stdOffset : TimeSpecification;

	var zonenames : Array<String>;

	public function new(
			name : String,
			julian:altdate.JulianDay,
			utcOffset:TimeSpecification,
			stdOffset:TimeSpecification)
	{
		this.name = name;
		this.julian = julian;
		this.utcOffset = utcOffset;
		this.stdOffset = stdOffset;
	}

	public function setZoneNames(zn : Array<String>) : Void {
		zonenames = zn;
	}

	public function findZoneInt(s:String) : Int {
		for(i in 0...zonenames.length) {
			if(zonenames[i] == s)
				return i;
		}
		throw "Zone name " + s + " not found";
		return -1;
	}

	public function toString() : String {
		var sb = new StringBuf();
		//sb.add("\t\t");
		sb.add('new ChangeRecord (');
		sb.add(findZoneInt(name));
		sb.add(', ');
		if(julian != null) {
			sb.add(julian);
			sb.add(", ");
		}
		else
			sb.add("-100000.0, ");
		sb.add(utcOffset.value + ", ");
		sb.add(stdOffset.value);
		sb.add(")");
		return sb.toString();
	}

	public function comment() : String {
		var sb = new StringBuf();
		sb.add(" // ");
		if(julian != null)
			sb.add(julian.toGregorianDateTime().toString());
		sb.add(" UTC");
		return sb.toString();
	}
}